<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'city.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		function getXMLHttpRequest(){
			var xhr=null;
			if((typeof XMLHttpRequest)!='undefined'){
				xhr=new XMLHttpRequest();
			}else{
				xhr=new ActiveXObject('Microsoft.XMLHttp');
			}
			return xhr;
		}
		
		function change(v1){
			var xhr=getXMLHttpRequest();
			xhr.open('post','city.do',true);
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4){
					var txt=xhr.responseText;
					var citys=eval("("+txt+")");
					document.getElementById('s2').innerHTML='';
					for(i=0;i<citys.length;i++){
						var op=new Option(citys[i].cityName,citys[i].cityValue);
						document.getElementById('s2').options[i]=op;
					}
				}
			};
			xhr.send('name='+v1);
		}
	</script>
  </head>
  
  <body>
    <select id="s1" style="width: 120px;" onchange="change(this.value);">
    	<option value="sh">上海</option>
    	<option value="bj">北京</option>
    </select>
    <select id="s2" style="width: 120px;"></select>
  </body>
</html>
